package com.wcy.controller.user;

import com.wcy.entity.UserLearningHistory;
import com.wcy.entity.UserRole;
import com.wcy.entity.pageVo.ApiDescriptor;
import com.wcy.entity.pageVo.ColumnConstructor;
import com.wcy.entity.pageVo.PageData;
import com.wcy.feign.user.FeignUserRoleService;
import jakarta.annotation.Resource;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Objects;

@RestController
public class UserRoleController {
    @Resource
    private FeignUserRoleService feignUserRoleService;

    @GetMapping("userRole/page")
    public ResponseEntity<PageData<UserRole>> getPage(@RequestParam(name = "pageNum",defaultValue = "1") int pageNum,
                                                      @RequestParam(name = "pageSize",defaultValue = "10") int pageSize) {
        return ResponseEntity.ok(new PageData<>(UserRole.class, Objects.requireNonNull(feignUserRoleService.getPage(pageNum, pageSize).getBody()),  new ApiDescriptor("userRole/add", "userRole/update", "userRole/delete"), ColumnConstructor.create()));
    }
    @GetMapping("userRole/list")
    public ResponseEntity<List<UserRole> > getList() {
        return feignUserRoleService.getList();
    }
    @PostMapping("userRole/add")
    public ResponseEntity<Void> add(@RequestBody UserRole userRole) {
        return feignUserRoleService.add(userRole);
    }
    @PutMapping("userRole/update")
    public ResponseEntity<Void> update(@RequestBody UserRole userRole) {
        return feignUserRoleService.update(userRole);
    }
    @DeleteMapping("userRole/delete/{id}")
    public ResponseEntity<Void> delete(@PathVariable Integer id) {
        return feignUserRoleService.delete(id);
    }

}
